package com.htz.java250805_library.entity;

import com.htz.java250805_library.enums.ResultCode;
import lombok.Data;



@Data
public class Result<T> {
    private Integer code;  //200 业务处理成功, 0 用户未登录   -1  后端出错了
    private String errMsg;
    private T data;

    public static <T> Result<T> unlogin(){
        Result<T> result = new Result<>();
        //未登录
        result.setCode(ResultCode.UNLOGIN.getCode());
        result.setErrMsg("用户未登录");
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FAIL.getCode());
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(int code, String errMsg){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result<T> fail(String errMsg, T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}











































